<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?php
$setup = new setup();
	$hostname_logon = 'localhost';      //Database server LOCATION
    $database_logon = 'wwwmsc_newcareer';       //Database NAME
    $username_logon = 'wwwmsc';       //Database USERNAME
    $password_logon = 'Slpnxhe}bX4h';       //Database PASSWORD
	$database_connection = mysql_connect($hostname_logon,$username_logon,$password_logon) or die("couldnt connect with mysql");
	$database_selection = mysql_select_db($database_logon,$database_connection);
	mysql_query( "SET NAMES utf8", $database_connection );
        mysql_query( "SET CHARACTER SET utf8", $database_selection );
// a? ??e? ???e? ? ?ata????s? eµfa???eta? t? a?t?st???? µ???µa, a????? eµfa???eta? ? f??µa ?ata????s??
if ($_GET['adRegistration'] == "success") 
{
	echo 'Your ad was added';
} 
else if($_GET['adRregistration'] == "failed") 
{
	echo 'Error: Your ad was not added';
}
else
{
	$ad_id = $_REQUEST["ad_id"];
	$ad_query = "select * from ADS where ad_id = '$ad_id'";
	$ad_result = mysql_query($ad_query) or die(mysql_error());
	$ad_data = mysql_fetch_array($ad_result);
?>
<br><br><br>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script language="javascript">
	function check_validation()
	{
		// validation for username
		if(document.getElementById("ad_title").value.split(" ").join("") == "")
		{
			alert("Please enter advertisement title.");
			document.getElementById("ad_title").focus();
			//jQuery("#user_name_error_value").html("Please enter username.");
			//jQuery("#user_name_error").fadeIn("slow");
			return false;
		}
		else
		{
			//jQuery("#user_name_error").fadeOut("slow");
		}
		
		// validation for users first name
		if(document.getElementById("ad_desc").value.split(" ").join("") == "")
		{
			alert("Please enter your advertisement description.");
			document.getElementById("ad_desc").focus();
			//jQuery("#user_fname_error_value").html("Please enter your first name.");
			//jQuery("#user_fname_error").fadeIn("slow");
			return false;
		}
		
		// validation for users last name
		if(document.getElementById("ad_code").value.split(" ").join("") == "")
		{
			alert("Please enter advertisement code.");
			document.getElementById("ad_code").focus();
			//jQuery("#user_lname_error_value").html("Please enter your surname.");
			//jQuery("#user_lname_error").fadeIn("slow");
			return false;
		}
		
		//http://www.w3resource.com/javascript/form/phone-no-validation.php
		// validation for users primary phone number
		if(document.getElementById("ad_type").value.split(" ").join("") == "")
		{
			alert("Please enter position type.");
			document.getElementById("ad_type").focus();
			//jQuery("#user_phone1_error_value").html("Please enter your primary phone number.");
			//jQuery("#user_phone1_error").fadeIn("slow");
			return false;
		}
		
		
		if(document.getElementById("ad_email").value.split(" ").join("") == "")
			{
				alert("Please enter advertisement email address.");
				//alert('Please enter your email address.'); 
				document.getElementById("ad_email").focus();
				//jQuery("#user_email_error_value").html("Please enter your location.");
				//jQuery("#user_email_error").fadeIn("slow");
				return false;
			}
			else
			{
				var emailPat=/^(.+)@(.+)$/
				var matchArray=document.getElementById("ad_email").value.match(emailPat)
			
				if (matchArray==null) 
				{
					//alert("")
					alert('The email address that you have entered is invalid.'); 
					document.getElementById("ad_email").focus();
					//jQuery("#user_email_error_value").html("The email address that you have entered is invalid.");
					//jQuery("#user_email_error").fadeIn("slow");
					return false;
				}
		}
		
		// validation for users location
		if(document.getElementById("autocomplete").value.split(" ").join("") == "")
		{
			alert("Please enter your location.");
			document.getElementById("autocomplete").focus();
			//jQuery("#autocomplete_error_value").html("Please enter your location.");
			//jQuery("#autocomplete_error").fadeIn("slow");
			return false;
		}
		
		if(document.getElementById("ad_catid").value.split(" ").join("") == "")
		{
			alert("Please enter advertisement category.");
			document.getElementById("ad_catid").focus();
			//jQuery("#user_website_error_value").html("The email address that you have entered is invalid.");
			//jQuery("#user_website_error").fadeIn("slow");
			return false;
		}
		
		if(document.getElementById("ad_salary").value.split(" ").join("") == "")
		{
			alert("Please enter indicative salary.");
			document.getElementById("ad_salary").focus();
			//jQuery("#user_website_error_value").html("The email address that you have entered is invalid.");
			//jQuery("#user_website_error").fadeIn("slow");
			return false;
		}
		
		return true;
	}
	function check_validation_of_field($value_of_field,$type_of_field)
	{
		if($value_of_field != "")
		{
			$.post( "http://192.185.116.17/~wwwmsc/includes/check_validation.php?field_type="+$type_of_field+"&field_value="+$value_of_field, function( data ) {
				if($type_of_field == "user_name")
				{
					if(data == "no_conflict")
					{
						jQuery("#user_name_error").fadeOut("slow");
					}
					else
					{
						jQuery("#user_name_error_value").html("The username that you have entered already exists, Please enter different username.");
						jQuery("#user_name_error").fadeIn("slow");
					}
				}
				else if($type_of_field == "user_email")
				{
					if(data == "no_conflict")
					{
						jQuery("#user_email_error").fadeOut("slow");
					}
					else
					{
						jQuery("#user_email_error_value").html("The email that you have entered already exists, Please enter different email.");
						jQuery("#user_email_error").fadeIn("slow");
					}
				}
			});
		}
	}
</script>
<div id="main">
    <div id="editUser">
Εισαγωγή Αγγελιας
<form name="AdsRegistrationForm" action="includes/EditAdsRegister.php" method="POST" onsubmit="javascript:return check_validation();">
	<table width="100%" border="0">
    	<tr>
        	<td width="100%" align="right">Τίτλος Θέσης::</td>
            <td width="100%" align="left"><input type="text" id="ad_title" name="ad_title"  size="30" value="<?php echo $ad_data["ad_title"]; ?>"></td>
        </tr>
    	<tr>
        	<td width="100%" align="right">Περιγραφή:</td>
            <td width="100%" align="left"><input type="text" id="ad_desc" name="ad_desc"  size="30" value="<?php echo $ad_data["ad_desc"]; ?>"></td>
        </tr>
    	<tr>
        	<td width="100%" align="right">Κωδικός Θέσης:</td>
            <td width="100%" align="left"><input type="text" id="ad_code" name="ad_code"  size="30" value="<?php echo $ad_data["ad_code"]; ?>"></td>
        </tr>
    	<tr>
        	<td width="100%" align="right">Τύπος Θέσης:</td>
            <td width="100%" align="left"><input type="text" id="ad_type" name="ad_type"  size="30" value="<?php echo $ad_data["ad_type"]; ?>"></td>
        </tr>
    	<tr>
        	<td width="100%" align="right">Email:</td>
            <td width="100%" align="left"><input type="text" id="ad_email" name="ad_email"  size="30" value="<?php echo $ad_data["ad_email"]; ?>"></td>
        </tr>
    	<tr>
        	<td width="100%" align="right">Address:</td>
            <td width="100%" align="left">
                <div id="locationField">
                  <input id="autocomplete" placeholder="??s??ete t? d?e????s? sa?"
                         onFocus="geolocate()" name="autocomplete" type="text" value="<?php echo $ad_data["user_autocomplete"]; ?>"></input>
                </div>
            
                <table id="address" hidden="true">
                  <tr>
                    <td class="label">Κατηγορία:</td>
                    <td class="slimField"><input class="field" id="street_number" name="street_number" disabled="true"></input></td>
                    <td class="wideField" colspan="2"><input class="field" id="route" name="route" disabled="true"></input></td>
                  </tr>
                  <tr>
                    <td class="label">Ενδεικτικός Μίσθος</td>
                    <td class="wideField" colspan="3"><input class="field" id="locality" name="locality" disabled="true"></input></td>
                  </tr>
                  <tr>
                    <td class="label">??µ??</td>
                    <td class="slimField"><input class="field" id="administrative_area_level_1" name="administrative_area_level_1" disabled="true"></input></td>
                    <td class="label">?.?.</td>
                    <td class="wideField"><input class="field" id="postal_code" name="postal_code" disabled="true"></input></td>
                  </tr>
                  <tr>
                    <td class="label">Country</td>
                    <td class="wideField" colspan="3"><input class="field"
                          id="country" disabled="true"></input></td>
                  </tr>
                </table>
            </td>
        </tr>
        <?php
			$ad_catid	=	$ad_data["ad_catid"];
			$category_select_query = "select cat_desc from CATEGORIES WHERE `cat_id` = '$ad_catid' limit 1";
			$category_select_result = mysql_query($category_select_query) or die(mysql_error());
			$category_name = mysql_result($category_select_result,0);
		?>
    	<tr>
        	<td width="100%" align="right">Κατηγορία:</td>
            <td width="100%" align="left"><input type="text" id="ad_catid" name="ad_catid"  value="<?php echo $category_name; ?>"  size="30"></td>
        </tr>
    	<tr>
        	<td width="100%" align="right">Ενδεικτικός Μίσθος:</td>
            <td width="100%" align="left">
            <input type="text" id="ad_salary" name="ad_salary" value="<?php echo $ad_data["ad_salary"]; ?>"  size="30">
            <input type="hidden" name="ad_id" id="ad_id" value="<?php echo $ad_id; ?>" />
            </td>
        </tr> 
    	<tr>
        	<td width="100%" align="right">&nbsp;</td>
            <td width="100%" align="left"><input type="Submit"  value="Καταχώρηση"></td>
        </tr> 
    </table>
</form>
<?php
}
?>
</div></div>